<script setup lang="ts">
import { defineComponent, h } from 'vue'
import {
  NConfigProvider,
  NDialogProvider,
  NLoadingBarProvider,
  NMessageProvider,
  NNotificationProvider,
  useDialog,
  useLoadingBar,
  useMessage,
  useNotification,
  enUS,
} from 'naive-ui'
import katex from 'katex'
import { useTheme } from '../common/useTheme'

import 'katex/dist/katex.min.css' // 引入 KaTeX 的样式
function registerNaiveTools() {
  window.$loadingBar = useLoadingBar()
  window.$dialog = useDialog()
  window.$message = useMessage()
  window.$notification = useNotification()
}

const NaiveProviderContent = defineComponent({
  name: 'NaiveProviderContent',
  setup() {
    registerNaiveTools()
    return {
      katex,
    }
  },
  render() {
    return h('div')
  },
})
const { theme, themeOverrides } = useTheme()
</script>

<template>
  <n-config-provider
    :katex="katex"
    :theme="theme"
    :theme-overrides="themeOverrides"
  >
    <NLoadingBarProvider>
      <NDialogProvider>
        <NNotificationProvider>
          <NMessageProvider>
            <slot />
            <NaiveProviderContent />
          </NMessageProvider>
        </NNotificationProvider>
      </NDialogProvider>
    </NLoadingBarProvider>
  </n-config-provider>
</template>
